import { useState } from "react";
import BaseCard from "components/BaseCard";
import { gql, useMutation } from "@apollo/client";
import { TextField, Stack, Button } from "@mui/material";
import { useSession } from "next-auth/react";
import toast from "react-hot-toast";
const ADD_COMMENT = gql`
  mutation Mutation($addCommentId: Int!, $content: String!) {
    addComment(id: $addCommentId, content: $content) {
      id
    }
  }
`;

const PostAddReview = ({ id, isShow }) => {
  const [review, setComment] = useState("");

  const [addComment, { data: d }] = useMutation(ADD_COMMENT);
  const { data: session } = useSession();
  const handleChange = (e) => {
    setComment(e.target.value);
  };
  const sendHandle = () => {
    // if (comment.length > 0)
    //   toast
    //     .promise(
    //       addComment({
    //         variables: {
    //           addCommentId: id,
    //           content: comment,
    //         },
    //       }),
    //       {
    //         loading: "正在发送",
    //         success: "发送成功",
    //         error: (err) => `发送失败 ${err}`,
    //       }
    //     )
    //     .then(() => {
    //       location.reload();
    //     });
    // else toast.error("评论内容不能为空！");
  };
  if (!isShow) return;
  return (
    <Stack direction="row" spacing={1}>
      <TextField onChange={handleChange} label="评论" fullWidth />
      <Button
        disabled={session?.user == undefined}
        onClick={sendHandle}
        variant="contained"
      >
        发送
      </Button>
    </Stack>
  );
};

export default PostAddReview;
